#!/bin/bash
# 安装编译依赖

set -e

GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'

echo -e "${GREEN}=== 安装编译依赖 ===${NC}"
echo ""

# 检测操作系统
if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
else
    echo -e "${RED}无法检测操作系统${NC}"
    exit 1
fi

echo "操作系统: $OS"
echo ""

case $OS in
    ubuntu|debian)
        echo -e "${YELLOW}安装 Ubuntu/Debian 依赖...${NC}"
        sudo apt-get update
        sudo apt-get install -y \
            build-essential \
            clang \
            libclang-dev \
            llvm-dev \
            pkg-config \
            libssl-dev
        ;;
    
    fedora|rhel|centos)
        echo -e "${YELLOW}安装 Fedora/RHEL/CentOS 依赖...${NC}"
        sudo dnf install -y \
            gcc \
            gcc-c++ \
            clang \
            clang-devel \
            llvm-devel \
            openssl-devel
        ;;
    
    arch|manjaro)
        echo -e "${YELLOW}安装 Arch Linux 依赖...${NC}"
        sudo pacman -S --noconfirm \
            base-devel \
            clang \
            llvm \
            openssl
        ;;
    
    *)
        echo -e "${RED}不支持的操作系统: $OS${NC}"
        echo "请手动安装以下依赖:"
        echo "  - clang"
        echo "  - libclang-dev"
        echo "  - llvm-dev"
        echo "  - pkg-config"
        echo "  - libssl-dev"
        exit 1
        ;;
esac

echo ""
echo -e "${GREEN}依赖安装完成${NC}"
echo ""
echo "验证安装:"
clang --version
echo ""
echo "现在可以运行: cargo build -p akoption-scheduler"
